package edu.sctu.zhengsenwen.month201506.day20150616;

import java.io.*;

/**
 * Created by user15 on 2015/6/16.
 */
public class BigStreamFileReadOrWrite {

    public static void main(String[] args) throws IOException {


        File inFile = new File("C:\\Users\\user15\\.gradle\\caches\\2.3");

        File outFile = new File("C:\\Users\\user15\\.gradle\\caches\\222.3");

        //最大流为69mb
        final int MAX_BYTE = 60000000;

        //接受的总容量
        long streamTotal = 0;

        //分流的容量
        int streamNum = 0;

        //剩余的字符
        int leave = 0;

        byte[] inOutbyte;


        FileInputStream fileInputStream = new FileInputStream(inFile);
        FileOutputStream fileOutputStream = new FileOutputStream(outFile);


        streamTotal = fileInputStream.available();

        streamNum = (int) Math.floor(streamTotal / MAX_BYTE);

        leave = (int) streamTotal % MAX_BYTE;


        if(streamNum >0){

            for(int i=0;i<streamNum;i++){

                inOutbyte = new byte[MAX_BYTE];

                fileInputStream.read(inOutbyte,0, MAX_BYTE);

                fileOutputStream.write(inOutbyte);

                fileOutputStream.flush();
            }
        }


        inOutbyte = new byte[leave];

        fileInputStream.read(inOutbyte,0,leave);

        fileOutputStream.write(inOutbyte);

        fileOutputStream.flush();

        fileOutputStream.close();
        fileInputStream.close();
        System.out.println("成功创建大文件 C:\\Users\\user15\\.gradle\\caches\\222.3 ");



    }
}
